/**
 * @format
 * @Author: TC
 * @Date: 2025-07-28 16:47:30
 * @Last Modified by: TC (tengchao@taqu.cn)
 * @Last Modified time: 2025-10-17 16:51:13
 */

import { BinFileData } from "db://assets/FrameWork/Util/BinUtility";
import { app } from "../../../../../FrameWork/App";
import { EMoleBundleConst } from "../Const/MoleBundleConst";
import { nsMoleEnum } from "../Const/MoleEunm";

/**
 * 预加载管理
 */
export class MolePreloadManager {
    public loadList = [this._loadCfg, this._loadMainUI, this._loadBattleUI, this._loadMole, this._loadCap];

    /**
     * 加载配置
     * @param cb
     */
    private _loadCfg(cb?: () => void): void {
        app.resMgr.loadBin(EMoleBundleConst.Mole, "Config/jsonCfg", (bin) => {
            if (!bin) {
                app.log.error("加载配置表失败");
                return;
            }
            app.bin.parseBin(bin, (binDataList: BinFileData[]) => {
                app.cfgMgr.praseAllCfgToJson(binDataList, () => {
                    app.log.log("加载配置表成功");
                    if (cb) cb();
                });
            });
        });
    }

    /**
     * 加载主界面
     * @param cb
     */
    private _loadMainUI(cb?: () => void): void {
        app.resMgr.loadPrefab(EMoleBundleConst.Mole, "Prefab/Main/MoleMainUI", () => {
            if (cb) cb();
        });
    }
    /**
     * 加载战斗界面界面
     * @param cb
     */
    private _loadBattleUI(cb?: () => void): void {
        app.resMgr.loadPrefab(EMoleBundleConst.Mole, "Prefab/Battle/MoleBattleUI", () => {
            if (cb) cb();
        });
    }

    /**
     * 加载地鼠
     * @param cb 回调
     */
    private _loadMole(cb?: Function): void {
        app.resMgr.loadPrefab(EMoleBundleConst.Mole, "Prefab/Battle/Mole/Mole", (p) => {
            app.poolMgr.addPool(nsMoleEnum.EPoolName.MOLE, p);
            app.resMgr.loadPrefab(EMoleBundleConst.Mole, "Prefab/Battle/Mole/MoleBlack", (p) => {
                app.poolMgr.addPool(nsMoleEnum.EPoolName.MOLE_BLACK, p);
                app.resMgr.loadPrefab(EMoleBundleConst.Mole, "Prefab/Battle/Mole/Rabbit", (p) => {
                    app.poolMgr.addPool(nsMoleEnum.EPoolName.RIBBIT, p);
                    app.resMgr.loadPrefab(EMoleBundleConst.Mole, "Prefab/Battle/Mole/Boss", (p) => {
                        app.poolMgr.addPool(nsMoleEnum.EPoolName.BOSS, p);
                        cb && cb();
                    });
                });
            });
        });
    }

    /**
     * 加载帽子
     * @param cb 回调
     */
    private _loadCap(cb?: Function): void {
        app.resMgr.loadPrefab(EMoleBundleConst.Mole, "Prefab/Battle/Item/Cap", (p) => {
            app.poolMgr.addPool(nsMoleEnum.EPoolName.CAP, p);
            cb && cb();
        });
    }
}
